package com.lhb.controller.admin;

import com.lhb.dto.CourseAddDTO;
import com.lhb.dto.CourseEditDTO;
import com.lhb.dto.CoursePageQueryDTO;
import com.lhb.entity.Course;
import com.lhb.result.PageResult;
import com.lhb.result.Result;
import com.lhb.service.CourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/admin/course")
@Slf4j
@Api(tags = "课程相关接口")
public class CourseController {

    @Autowired
    private CourseService courseService;

    @GetMapping("/pageQuery")
    @ApiOperation("分页查询")
    public Result<PageResult> pageQuery(CoursePageQueryDTO coursePageQueryDTO) {

        log.info("课程分页查询:{}", coursePageQueryDTO);

        PageResult pageResult=courseService.pageQuery(coursePageQueryDTO);

        return Result.success(pageResult);
    }

    @PostMapping
    @ApiOperation("添加课程成绩")
    public Result add(@RequestBody CourseAddDTO courseAddDTO)
    {
        log.info("添加课程成绩:{}",courseAddDTO);


        courseService.add(courseAddDTO);

        return Result.success();


    }

    @PutMapping
    @ApiOperation("编辑课程信息")
    public Result edit(@RequestBody CourseEditDTO courseEditDTO)
    {
        log.info("编辑课程信息:{}",courseEditDTO);

        courseService.edit(courseEditDTO);


        return Result.success();


    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除课程")
    public Result delete(@PathVariable Long id)
    {
        log.info(" 删除id为:{} 的课程",id);

        courseService.delete(id);

        return Result.success();
    }

    @PostMapping("/export")
    @ApiOperation("导出Excel报表")
    public void export(HttpServletResponse response, @RequestBody ArrayList<Course> list)
    {
        courseService.export(response,list);
    }



    



}
